package org.jawa.model;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;

import java.io.Serializable;

@Entity
@Table(name = "product")
public class Product extends BaseObject implements Serializable {
	
	private static final long serialVersionUID = -2814503183381189326L;
	private Long id;
	private Shop shop;
	private Category category;
	private User user;
	private String productname;
	private Integer productnum;
	private String productphoto;
	private String productpreview;
	private String productdesc;
	private Double price;
	private Integer productauction;
	private Date pubdate;
	private Date endselldate;
	private Integer hit;
	private Date updatedate;
	private Character locked;
	private Set<Auction> auctions = new HashSet<Auction>(0);
	private Set<Order> orders = new HashSet<Order>(0);
	private Set<Favorite> favorites = new HashSet<Favorite>(0);
	private Set<Inquire> inquires = new HashSet<Inquire>(0);

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public Long getId() {
		return this.id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "SHOPID")
	public Shop getShop() {
		return this.shop;
	}

	public void setShop(Shop shop) {
		this.shop = shop;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "CATEGORYID")
	public Category getCategory() {
		return this.category;
	}

	public void setCategory(Category category) {
		this.category = category;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "USERID")
	public User getUser() {
		return this.user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	@Column(name = "PRODUCTNAME")
	public String getProductname() {
		return this.productname;
	}

	public void setProductname(String productname) {
		this.productname = productname;
	}

	@Column(name = "PRODUCTNUM")
	public Integer getProductnum() {
		return this.productnum;
	}

	public void setProductnum(Integer productnum) {
		this.productnum = productnum;
	}

	@Column(name = "PRODUCTPHOTO")
	public String getProductphoto() {
		return this.productphoto;
	}

	public void setProductphoto(String productphoto) {
		this.productphoto = productphoto;
	}

	@Column(name = "PRODUCTPREVIEW")
	public String getProductpreview() {
		return this.productpreview;
	}

	public void setProductpreview(String productpreview) {
		this.productpreview = productpreview;
	}

	@Column(name = "PRODUCTDESC", length = 1000)
	public String getProductdesc() {
		return this.productdesc;
	}

	public void setProductdesc(String productdesc) {
		this.productdesc = productdesc;
	}

	@Column(name = "PRICE", precision = 22, scale = 0)
	public Double getPrice() {
		return this.price;
	}

	public void setPrice(Double price) {
		this.price = price;
	}

	@Column(name = "PRODUCTAUCTION")
	public Integer getProductauction() {
		return this.productauction;
	}

	public void setProductauction(Integer productauction) {
		this.productauction = productauction;
	}

	@Temporal(TemporalType.DATE)
	@Column(name = "PUBDATE", length = 0)
	public Date getPubdate() {
		return this.pubdate;
	}

	public void setPubdate(Date pubdate) {
		this.pubdate = pubdate;
	}

	@Temporal(TemporalType.DATE)
	@Column(name = "ENDSELLDATE", length = 0)
	public Date getEndselldate() {
		return this.endselldate;
	}

	public void setEndselldate(Date endselldate) {
		this.endselldate = endselldate;
	}

	@Column(name = "HIT")
	public Integer getHit() {
		return this.hit;
	}

	public void setHit(Integer hit) {
		this.hit = hit;
	}

	@Temporal(TemporalType.DATE)
	@Column(name = "UPDATEDATE", length = 0)
	public Date getUpdatedate() {
		return this.updatedate;
	}

	public void setUpdatedate(Date updatedate) {
		this.updatedate = updatedate;
	}

	@Column(name = "LOCKED", length = 1)
	public Character getLocked() {
		return this.locked;
	}

	public void setLocked(Character locked) {
		this.locked = locked;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "product")
	public Set<Auction> getAuctions() {
		return this.auctions;
	}

	public void setAuctions(Set<Auction> auctions) {
		this.auctions = auctions;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "product")
	public Set<Order> getOrders() {
		return this.orders;
	}

	public void setOrders(Set<Order> orders) {
		this.orders = orders;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "product")
	public Set<Favorite> getFavorites() {
		return this.favorites;
	}

	public void setFavorites(Set<Favorite> favorites) {
		this.favorites = favorites;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "product")
	public Set<Inquire> getInquires() {
		return this.inquires;
	}

	public void setInquires(Set<Inquire> inquires) {
		this.inquires = inquires;
	}

	public boolean equals(Object o) {
		if (this == o)
			return true;
		if (o == null || getClass() != o.getClass())
			return false;

		Product pojo = (Product) o;

		if (shop != null ? !shop.equals(pojo.shop) : pojo.shop != null)
			return false;
		if (category != null ? !category.equals(pojo.category)
				: pojo.category != null)
			return false;
		if (user != null ? !user.equals(pojo.user) : pojo.user != null)
			return false;
		if (productname != null ? !productname.equals(pojo.productname)
				: pojo.productname != null)
			return false;
		if (productnum != null ? !productnum.equals(pojo.productnum)
				: pojo.productnum != null)
			return false;
		if (productphoto != null ? !productphoto.equals(pojo.productphoto)
				: pojo.productphoto != null)
			return false;
		if (productpreview != null ? !productpreview
				.equals(pojo.productpreview) : pojo.productpreview != null)
			return false;
		if (productdesc != null ? !productdesc.equals(pojo.productdesc)
				: pojo.productdesc != null)
			return false;
		if (price != null ? !price.equals(pojo.price) : pojo.price != null)
			return false;
		if (productauction != null ? !productauction
				.equals(pojo.productauction) : pojo.productauction != null)
			return false;
		if (pubdate != null ? !pubdate.equals(pojo.pubdate)
				: pojo.pubdate != null)
			return false;
		if (endselldate != null ? !endselldate.equals(pojo.endselldate)
				: pojo.endselldate != null)
			return false;
		if (hit != null ? !hit.equals(pojo.hit) : pojo.hit != null)
			return false;
		if (updatedate != null ? !updatedate.equals(pojo.updatedate)
				: pojo.updatedate != null)
			return false;
		if (locked != null ? !locked.equals(pojo.locked) : pojo.locked != null)
			return false;

		return true;
	}

	public int hashCode() {
		int result = 0;
		result = (shop != null ? shop.hashCode() : 0);
		result = 31 * result + (category != null ? category.hashCode() : 0);
		result = 31 * result + (user != null ? user.hashCode() : 0);
		result = 31 * result
				+ (productname != null ? productname.hashCode() : 0);
		result = 31 * result + (productnum != null ? productnum.hashCode() : 0);
		result = 31 * result
				+ (productphoto != null ? productphoto.hashCode() : 0);
		result = 31 * result
				+ (productpreview != null ? productpreview.hashCode() : 0);
		result = 31 * result
				+ (productdesc != null ? productdesc.hashCode() : 0);
		result = 31 * result + (price != null ? price.hashCode() : 0);
		result = 31 * result
				+ (productauction != null ? productauction.hashCode() : 0);
		result = 31 * result + (pubdate != null ? pubdate.hashCode() : 0);
		result = 31 * result
				+ (endselldate != null ? endselldate.hashCode() : 0);
		result = 31 * result + (hit != null ? hit.hashCode() : 0);
		result = 31 * result + (updatedate != null ? updatedate.hashCode() : 0);
		result = 31 * result + (locked != null ? locked.hashCode() : 0);

		return result;
	}

	public String toString() {
		StringBuffer sb = new StringBuffer(getClass().getSimpleName());

		sb.append(" [");
		sb.append("id").append("='").append(getId()).append("', ");
		sb.append("shop").append("='").append(getShop()).append("', ");
		sb.append("category").append("='").append(getCategory()).append("', ");
		sb.append("user").append("='").append(getUser()).append("', ");
		sb.append("productname").append("='").append(getProductname()).append(
				"', ");
		sb.append("productnum").append("='").append(getProductnum()).append(
				"', ");
		sb.append("productphoto").append("='").append(getProductphoto())
				.append("', ");
		sb.append("productpreview").append("='").append(getProductpreview())
				.append("', ");
		sb.append("productdesc").append("='").append(getProductdesc()).append(
				"', ");
		sb.append("price").append("='").append(getPrice()).append("', ");
		sb.append("productauction").append("='").append(getProductauction())
				.append("', ");
		sb.append("pubdate").append("='").append(getPubdate()).append("', ");
		sb.append("endselldate").append("='").append(getEndselldate()).append(
				"', ");
		sb.append("hit").append("='").append(getHit()).append("', ");
		sb.append("updatedate").append("='").append(getUpdatedate()).append(
				"', ");
		sb.append("locked").append("='").append(getLocked()).append("', ");

		sb.append("]");

		return sb.toString();
	}

}
